'use strict';

/**
 * @description 用户信息表模型
 * */
module.exports = app => {
  const { STRING, INTEGER, TEXT } = app.Sequelize;

  const UserInfo = app.model.define('userInfo', {
    firstName: {
      type: STRING(20),
      allowNull: true,
      comment: '姓',
    },
    secondName: {
      type: STRING(20),
      allowNull: true,
      comment: '名',
    },
    avatar: {
      type: TEXT,
      allowNull: true,
      comment: '头像',
    },
    description: {
      type: TEXT,
      allowNull: true,
      comment: '描述',
    },
    phoneNum: {
      type: STRING(20),
      allowNull: true,
      comment: '电话号码',
    },
    address: {
      type: STRING(100),
      allowNull: true,
      comment: '具体地址',
    },
    areaId: {
      type: INTEGER,
      allowNull: true,
      comment: '地区id',
    },
    uid: {
      type: INTEGER,
      allowNull: true,
      comment: '用户id',
    },
  });

  UserInfo.associate = () => {
    app.model.UserInfo.belongsTo(app.model.User, {
      foreignKey: 'uid',
    });
    app.model.UserInfo.belongsTo(app.model.Area, {
      foreignKey: 'areaId',
    });
  };

  return UserInfo;
};
